using System.ComponentModel;

namespace WB.Mvc.Forms
{
	/// <summary>
	/// Strategy that creates a <see cref="Field"/> from a <see cref="string"/> <see cref="PropertyDescriptor"/>.
	/// </summary>
	public class StringToCharFieldStrategy : CharFieldStrategy, IModelFieldStrategy
	{
		/// <summary>
		/// Creates a <see cref="Field"/> from <paramref name="descriptor"/>.
		/// </summary>
		/// <param name="descriptor">
		/// Model for <see cref="Field"/>.
		/// </param>
		/// <returns>
		/// <see cref="Field"/> if <paramref name="descriptor.PropertyType"/> 
		/// is <see cref="string"/>; <c>null</c> otherwise.
		/// </returns>
		public Field Create(PropertyDescriptor descriptor)
		{
			if (descriptor.PropertyType != typeof(string))
				return null;
			if (descriptor.IsReadOnly)
				return null;
			
			return Create(descriptor.Name);
		}
	}
}